package com.qf.service;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/10/18 17:00
 * description:路由策略:根据归属不同发送不同运营商
 */
@Service(value = "router")
@Slf4j
public class RouterServiceImpl  implements  FilerChainService{

    @Autowired
    private AmqpAdmin amqpAdmin;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[路由策略模块]路由策略开始执行,StandardSubmit={}",standardSubmit);
        //1.封装队列名称,根据运行商ID进行封装
      String queueName=RabbitMQConstants.TOPIC_SMS_GATEWAY+standardSubmit.getGatewayID();
        //2.创建指定的队列
        amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
        //3.发送消息,根据运营商ID,将短信数据发送到对应的运行商队列中
        rabbitTemplate.convertAndSend(queueName,standardSubmit);
        log.info("[路由策略模块]路由策略执行成功,短信数据路由到={},StandardSubmit={}",queueName,standardSubmit);

        return true;
    }
}
